package com.shopping.tools;

import java.util.ArrayList;
import java.util.HashMap;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.shopping.Model.ActivityListModel;
import com.shopping.Model.CreatorModel;
import com.shopping.Model.PhotoCommentRowModel;
import com.shopping.Model.PhotoWallDetailModel;
import com.shopping.Model.ReceiverModel;

/**
 * CategoryListTools单例模式
 * 
 */
public class CategoryListTools {
	private static CategoryListTools mcategoryListTools = null;

	private CategoryListTools() {

	}

	public static CategoryListTools getCategoryListTools() {
		if (mcategoryListTools == null) {
			mcategoryListTools = new CategoryListTools();
		}
		return mcategoryListTools;
	}

	/**
	 * 对商家列表数据进行解析
	 */
	 ActivityListModel mActivityListModel;
	
	 public ArrayList<ActivityListModel> getActivityListModel(String path,
	 ArrayList<ActivityListModel> activityList) {
	 try {
	 JSONObject jsonObject = new JSONObject(path);
	 JSONObject jsonBody = jsonObject.getJSONObject("body");
	 JSONArray jsonArray = (JSONArray) jsonBody.get("rows");
	 for (int i = 0; i < jsonArray.length(); i++) {
	 JSONObject jsonObject2 = jsonArray.getJSONObject(i);
	 mActivityListModel = new ActivityListModel();
	 mActivityListModel.setId(jsonObject2.getString("id"));
	 mActivityListModel.setAddress(jsonObject2.getString("address"));
	 mActivityListModel.setCoverThumbnail(jsonObject2
	 .getString("coverThumbnail"));
	 mActivityListModel.setShopName(jsonObject2
	 .getString("shopName"));
	 System.out.println("------shopName-------"
	 + jsonObject2.getString("shopName"));
	 mActivityListModel.setStopId(jsonObject2.getString("stopId"));
	 mActivityListModel.setTitle(jsonObject2.getString("title"));
	 mActivityListModel.setVisitCount(jsonObject2
	 .getString("visitCount"));
	
	 activityList.add(mActivityListModel);
	 }
	 return activityList;
	 } catch (JSONException e) {
	 // TODO Auto-generated catch block
	 e.printStackTrace();
	 return null;
	 }
	
	 }
	// 对推荐活动数据进行json解析
	public static ArrayList<HashMap<String, String>> json_PromoteActivity(
			String str, ArrayList<HashMap<String, String>> list) {
		HashMap<String, String> map;
		try {
			JSONObject jsonObject = new JSONObject(str);
			JSONObject jsonbody = jsonObject.getJSONObject("body");
			JSONArray jsonArray = (JSONArray) jsonbody.get("rows");
			for (int i = 0; i < jsonArray.length(); i++) {
				map = new HashMap<String, String>();
				JSONObject jsonObject2 = (JSONObject) jsonArray.get(i);
				map.put("PA_id", jsonObject2.getString("id"));
				map.put("PA_address", jsonObject2.getString("address"));
				map.put("PA_coverThumbnail",
						Constant.URL + jsonObject2.getString("coverThumbnail"));
				map.put("PA_stopId", jsonObject2.getString("shopId"));
				map.put("PA_title", jsonObject2.getString("title"));
				map.put("PA_visitCount", jsonObject2.getString("visitCount"));
				map.put("PA_shopName", jsonObject2.getString("shopName"));
				list.add(map);
			}

		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return list;
	}

	// 照片墙详情json解析
	PhotoWallDetailModel mPhotoWallDetailModel;

	public ArrayList<PhotoWallDetailModel> getPhotoWallDetailModel(
			String urlPath, ArrayList<PhotoWallDetailModel> detailList) {
		System.out.println("+++jsonstr++" + urlPath);
		try {
			JSONObject jsonObject = new JSONObject(urlPath);
			JSONObject jsonBody = jsonObject.getJSONObject("body");
			mPhotoWallDetailModel = new PhotoWallDetailModel();
			mPhotoWallDetailModel.setId(jsonBody.getString("id"));
			mPhotoWallDetailModel.setPhotoThumbnail(Constant.URL
					+ jsonBody.getString("photoThumbnail"));
			mPhotoWallDetailModel.setIsPraised(jsonBody.getString("isPraised"));
			mPhotoWallDetailModel.setPhotoOrigin(Constant.URL
					+ jsonBody.getString("photoOrigin"));
			mPhotoWallDetailModel.setPraiseCount(jsonBody
					.getString("praiseCount"));
			mPhotoWallDetailModel.setSummary(jsonBody.getString("summary"));
			System.out.println("--------summary:"
					+ jsonBody.getString("summary"));

			detailList.add(mPhotoWallDetailModel);

			return detailList;
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}

	// 对照片墙数据进行json解析
	public static ArrayList<HashMap<String, String>> json_PhotoWallComment(
			String str, ArrayList<HashMap<String, String>> list) {
		HashMap<String, String> map;
		try {
			JSONObject jsonObject = new JSONObject(str);
			JSONObject jsonbody = jsonObject.getJSONObject("body");
			JSONArray jsonArray = (JSONArray) jsonbody.get("rows");
			for (int i = 0; i < jsonArray.length(); i++) {
				map = new HashMap<String, String>();
				JSONObject jsonObject2 = (JSONObject) jsonArray.get(i);
				map.put("comment_content", jsonObject2.getString("content"));
				map.put("comment_createTime",
						jsonObject2.getString("createTime"));
				JSONObject jsoncretor = jsonObject2.getJSONObject("creator");
				map.put("creator_name", jsoncretor.getString("name"));
				map.put("creator_headPhoto", jsoncretor.getString("headPhoto"));
				System.out.println("------creatorname-------"
						+ jsoncretor.getString("name"));
				list.add(map);
			}

		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return list;
	}

	/**
	 * 对照片墙评论数据进行解析
	 */

	public ArrayList<PhotoCommentRowModel> getPhotoCommentRowModel(String path,
			ArrayList<PhotoCommentRowModel> commentList) {
		try {
			JSONObject jsonObject = new JSONObject(path);
			JSONObject jsonBody = jsonObject.getJSONObject("body");
			JSONArray jsonArray = (JSONArray) jsonBody.get("rows");
			PhotoCommentRowModel mPhotoCommentRowModel;
			for (int i = 0; i < jsonArray.length(); i++) {
				JSONObject jsonObject2 = jsonArray.getJSONObject(i);
				mPhotoCommentRowModel = new PhotoCommentRowModel();
				mPhotoCommentRowModel.setId(jsonObject2.getString("id"));
				mPhotoCommentRowModel.setParentId(jsonObject2
						.getString("parentId"));
				mPhotoCommentRowModel.setContent(jsonObject2
						.getString("content"));
				mPhotoCommentRowModel.setCreateTime(jsonObject2
						.getString("createTime"));
				System.out.println("------creatorTime-------"
						+ jsonObject2.getString("createTime"));
				mPhotoCommentRowModel.setContentType(jsonObject2
						.getString("contentType"));
				CreatorModel mCreatorModel;
				ArrayList<CreatorModel> creatorList = new ArrayList<CreatorModel>();
				JSONObject jsoncretor = jsonObject2.getJSONObject("creator");
				mCreatorModel = new CreatorModel();
				mCreatorModel.setId(jsoncretor.getString("id"));
				mCreatorModel.setHeadPhoto(jsoncretor.getString("headPhoto"));
				mCreatorModel.setName(jsoncretor.getString("name"));
				creatorList.add(mCreatorModel);
				System.out.println("------creatorname-------"
						+ jsoncretor.getString("name"));
				ReceiverModel mReceiverModel;
				ArrayList<ReceiverModel> receiverList = new ArrayList<ReceiverModel>();
				JSONObject jsonreceiver = jsonObject2.getJSONObject("receiver");
				mReceiverModel = new ReceiverModel();
				mReceiverModel.setId(jsonreceiver.getString("id"));
				mReceiverModel.setName(jsonreceiver.getString("name"));
				receiverList.add(mReceiverModel);

				mPhotoCommentRowModel.setCreatorList(creatorList);
				mPhotoCommentRowModel.setReceiverList(receiverList);
				commentList.add(mPhotoCommentRowModel);
			}
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return commentList;

	}

	// 对照片墙数据进行json解析
	public static ArrayList<HashMap<String, String>> json_PhotoWall(String str,
			ArrayList<HashMap<String, String>> list) {
		HashMap<String, String> map;
		try {
			JSONObject jsonObject = new JSONObject(str);
			JSONObject jsonbody = jsonObject.getJSONObject("body");
			JSONArray jsonArray = (JSONArray) jsonbody.get("rows");
			for (int i = 0; i < jsonArray.length(); i++) {
				map = new HashMap<String, String>();
				JSONObject jsonObject2 = (JSONObject) jsonArray.get(i);
				map.put("photoWall_id", jsonObject2.getString("id"));
				map.put("photoThumbnail",
						Constant.URL + jsonObject2.getString("photoThumbnail"));
				map.put("praiseCount", jsonObject2.getString("praiseCount"));
				map.put("summary", jsonObject2.getString("summary"));
				list.add(map);
				System.out.println("------summary------"
						+ jsonObject2.getString("summary"));

			}

		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return list;
	}

	/**
	 * 对PhotoWall数据进行json解析
	 */
	// PhotoWallRowModel mPhotoWallRowModel;
	//
	// public ArrayList<PhotoWallRowModel> getPhotoWallRowModel(String urlPath,
	// ArrayList<PhotoWallRowModel> RowList) {
	// System.out.println("+++jsonstr++" + urlPath);
	// try {
	// JSONObject jsonObject = new JSONObject(urlPath);
	// JSONObject jsonbody = jsonObject.getJSONObject("body");
	// // String rows = jsonbody.getString("rows");
	// // System.out.println("22222222222222" + rows);
	// // JSONArray jsonArray = new JSONArray(rows);
	// JSONArray jsonArray = (JSONArray) jsonbody.get("rows");
	// System.out.println("jsonArray.length" + jsonArray.length());
	// for (int i = 0; i < jsonArray.length(); i++) {
	// JSONObject jsonObject2 = jsonArray.getJSONObject(i);
	// mPhotoWallRowModel = new PhotoWallRowModel();
	// mPhotoWallRowModel.setId(jsonObject2.getString("id"));
	// mPhotoWallRowModel.setPhotoThumbnail(jsonObject2
	// .getString("photoThumbnail"));
	// System.out.println("summary:"
	// + jsonObject2.getString("summary"));
	// mPhotoWallRowModel.setSummary(jsonObject2.getString("summary"));
	// mPhotoWallRowModel.setPraiseCount(jsonObject2
	// .getString("praiseCount"));
	// RowList.add(mPhotoWallRowModel);
	// }
	// return RowList;
	// } catch (Exception e) {
	// e.printStackTrace();
	// return null;
	// }
	// }

}
